package com.thz.friend.service.file.impl;

import com.aliyun.oss.ServiceException;
import com.thz.common.core.enums.ResultCode;
import com.thz.common.core.result.Result;
import com.thz.exception.ApplicationException;
import com.thz.file.pojo.OSSResult;
import com.thz.file.service.OSSService;
import com.thz.friend.service.file.IFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.UUID;

/**
 * @Description
 * @Author thz
 * @Date 2025/3/29
 */
@Slf4j
@Service
public class FileServiceImpl implements IFileService {

    @Autowired
    private OSSService ossService;

    @Override
    public OSSResult upload(MultipartFile file) {
        try {
            return ossService.uploadFile(file);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new ApplicationException(Result.failed(ResultCode.FAILED_FILE_UPLOAD));
        }
    }


}
